﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using ThouShaltNotBrick.Models;
using GameUtils.GeneralObjects;
using GameUtils.Resources;

namespace ThouShaltNotBrick.Logic.Resources
{
    public sealed class GameResources : IResourceContainer
    {
        #region Constants
        private const string DATA_DIR_PATH = @"Data\";
        private const string CAMPAIGNS_DIR_PATH = DATA_DIR_PATH + @"Campaigns\";

        private const string BRICK_STATES_PATH = DATA_DIR_PATH + "BrickStates";
        private const string BRICK_TYPES_PATH = DATA_DIR_PATH + "BrickTypes";
        private const string CAMPAIGNS_PATH = DATA_DIR_PATH + "Campaigns";
        #endregion

        #region Properties
        public BrickStatesData BrickStatesData { get; private set; }
        public BrickTypesData BrickTypesData { get; private set; }
        public CampaignsData CampaignsData { get; private set; }

        private Dictionary<string, CampaignData> mCampaignDataDict;
        private Dictionary<string, Dictionary<string, LevelData>> mLevelDataDictForCampaignDict;
        #endregion

        #region Overriden Methods
        public void Initialize(ContentManager pContentManager)
        {
            BrickStatesData = pContentManager.Load<BrickStatesData>(BRICK_STATES_PATH);
            BrickTypesData = pContentManager.Load<BrickTypesData>(BRICK_TYPES_PATH);
            CampaignsData = pContentManager.Load<CampaignsData>(CAMPAIGNS_PATH);

            mCampaignDataDict = pContentManager.LoadContent<CampaignData>(CAMPAIGNS_DIR_PATH);

            mLevelDataDictForCampaignDict = new Dictionary<string, Dictionary<string, LevelData>>();
            List<string> campaignNames = CampaignsData.GetCampaigns();
            foreach (string campaignName in campaignNames)
            {
                Dictionary<string, LevelData> levelDataDict =
                    pContentManager.LoadContent<LevelData>(CAMPAIGNS_DIR_PATH + campaignName + "\\");
                mLevelDataDictForCampaignDict.Add(campaignName, levelDataDict);
            }
        }
        #endregion

        #region Methods
        public CampaignData GetCampaignData(string pCampaignName)
        {
            return mCampaignDataDict[pCampaignName];
        }

        public LevelData GetLevelData(string pCampaignName, string pLevelName)
        {
            return mLevelDataDictForCampaignDict[pCampaignName][pLevelName];
        }
        #endregion
    }
}